package com.czy;

import java.io.*;
import java.nio.file.Files;

public class MySQL8表sql改为MySQL5 {
    public static void main(String[] args) throws IOException {
        // mysql 8.0 sql删除排序规则
        File file = new File("d:\\新建文件夹");
        for (File listFile : file.listFiles()) {
            File tmp = Files.createTempFile("tmp_", ".sql").toFile();
            BufferedWriter bw = new BufferedWriter(new FileWriter(tmp));
            BufferedReader br = new BufferedReader(new FileReader(listFile));

            String s;
            while ((s = br.readLine()) != null) {
                s = s.replace("COLLATE utf8mb4_0900_ai_ci", "");
                s = s.replace("COLLATE=utf8mb4_0900_ai_ci","");
                bw.write(s);
                bw.newLine();
            }

            br.close();
            bw.close();
            listFile.delete();
            tmp.renameTo(listFile);
        }
    }
}